#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#




import wsgiref.handlers
#import os

from google.appengine.ext import webapp
from google.appengine.ext import db

from google.appengine.ext.webapp import template


class Property(db.Model):
	Address1 = db.StringProperty(required=True)
	Address2 = db.StringProperty()
	City = db.StringProperty()
	Province = db.StringProperty()
	PostalCode = db.StringProperty()
	Owner = db.StringProperty()
	Description = db.StringProperty()
	
class Unit(db.Model):
	PropertyID = db.IntegerProperty()
	Status = db.StringProperty(choices=set(["Vacant", "Occupied", "Construction"]))
	Bedrooms = db.IntegerProperty()
	Bathrooms = db.IntegerProperty()
	Appliances = db.StringProperty()
	Rent = db.FloatProperty()
	Extras = db.StringProperty()
	Description = db.StringProperty()

class Tenant(db.Model):
	UnitID = db.IntegerProperty()
	Name = db.StringProperty()
	Homenumber = db.StringProperty()
	Cellnumber = db.StringProperty()
	Email = db.StringProperty()
	Address1 = db.StringProperty()
	Address2 = db.StringProperty()
	City = db.StringProperty()
	Province = db.StringProperty()
	PostalCode = db.StringProperty()
	Employer = db.StringProperty()
	DriversLicense = db.StringProperty()
	
	
class MainHandler(webapp.RequestHandler):

  def get(self):
    self.response.out.write("""
	  <html>
        <body>
          Hello World!<br>
		  <a href="/newproperty">New Property</a>
        </body>
      </html>
	""")



class NewProperty(webapp.RequestHandler):
  
	def get(self):
	
		template_values = {}
		self.response.out.write(template.render("newproperty.html",template_values))
	
	def post(self):
		property = Property(
							Address1 = self.request.get('Address1'),
							Address2 = self.request.get('Address2'),
							City = self.request.get('City'),
							Province = self.request.get('Province'),
							PostalCode = self.request.get('PostalCode'),
							Owner = self.request.get('Owner'),
							Description = self.request.get('Description'),
							)
		property.put()


def main():
  application = webapp.WSGIApplication([('/', MainHandler),
										('/newproperty', NewProperty)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()
